#pragma once

#include <boost/unordered_map.hpp>

#include <engine.core/System.hpp>
#include <engine.core/qt_hash.hpp>
#include <engine.video/VideoDevice.hpp>
#include <engine.audio/AudioDevice.hpp>

#include "exports.hpp"




class ENGINE_RESOURCE_API ResourceSystem : public System
{
public:

	typedef boost::function<Texture::ptr(QString)>       TextureLoad;

	typedef boost::unordered_map<QString,EffectPtr>    EffectMap;
	typedef boost::unordered_map<QString,TexturePtr>   TextureMap;

private:

	VideoDevicePtr        m_videoDevice;
	AudioDevicePtr        m_audioDevice;

	EffectMap             m_effects;
	//EffectMap::iterator    m_current;
	TextureMap            m_textures;
	//TextureMap::iterator   


	TextureLoad           m_textureFN;

public:

	ResourceSystem(const VideoDevicePtr& videoDevice, const AudioDevicePtr& audioDevice);



	/**
	 * Get the name of this System.
	 */
	QString name() const;

	/**
	 * Update this system.
	 */
	void update();



	/**
	 * Get the effect with the given name.
	 * The effect is loaded when it's not present.
	 *
	 * In case the effect is not managed by the ResourceSystem
	 * it is created.
	 */
	EffectPtr createEffect(QString name, bool* created = NULL);

	/**
	 * Get the Texture with the given name.
	 * The texture is loaded when it's not present.
	 *
	 * In case the texture is not managed by the ResourceSystem
	 * it is loaded from the HD (by default), but this may
	 * be changed by setting the TextureLoad functor to a user defined
	 * function.
	 */
	TexturePtr createTexture(QString fname, bool* created = NULL);

	void clearCache();



	void setFunctor(TextureLoad fn);
};
///////////////////////////////////////////////////////////////////////////////////////////////////

DEFINE_STRICT_PTR(ResourceSystem)
